<?php
   $table = $this->uri->segment(3,0);
   $url_ajax = base_url().'admin/ajax_field/order';
   $url_ajax_sotrang = base_url().'admin/ajax_field/num';
   $url_ajax_pub = base_url().'admin/ajax_field/pub/'.$table;
   $url_ajax_where = base_url().'admin/ajax_field/where/'.$table;
   ?>
<!-- Noi dung bai viet-->
<script>
   $(document).ready(function(){
       //*******************AJAX HIEN****************************************
       $('.ajax_hien').click(function(){
           var name = $(this).attr('name');
           var nclass = $(this).attr('class');
           var data =0;
           if(nclass=="ajax_hien"){
               data =0;
           }else{
               data=1;
           }
           var diachi = '<?php echo base_url().'admin/ajax/';?>'+name;
           //alert(diachi);       
           $.ajax({
             		type: "POST",
             		url: diachi,
             		data: {data: data},
                   success: succes,
                   error: err
           		});
       })
       //*******************order ajax****************************************
       $(".box_noidung .ajax").click(function () {       
           //$('.loading').html('fdsfds');
           var data= $(this).attr('href');
           var url1 = '<?php echo $url_ajax;?>';
           $.ajax({
             		type: "POST",
             		url: url1,
             		data: {data: data},
                   success: callback,
                   error: err
           		});
            
           return false;
       });
       //********************* loc du lieu***********************************
       $(".chon_danhmuc .locdulieu").change(function () {       
           //$('.loading').html('fdsfds');
           var data= $(this).val();
           var url2 = '<?php echo $url_ajax_where;?>';
           $.ajax({
             		type: "POST",
             		url: url2,
             		data: {data: data},
                   success: callback,
                   error: err
           		});
            
           return false;
       });
       //*********************chon so trang**********************************
       $(".chon_trang #sotrang").change(function () {       
           //$('.loading').html('fdsfds');
           var data= $(this).val();
           var url2 = '<?php echo $url_ajax_sotrang;?>';
           $.ajax({
             		type: "POST",
             		url: url2,
             		data: {data: data},
                   success: callback,
                   error: err
           		});
            
           return false;
       });
       function succes (data, status){
          // var id = '#p'+data;
           //alert(id);
           $(data).toggleClass('untopbot');
       }
       function callback(data, status){
           location.reload();
           //$("div .box_ajax").html(data);
         }
       
   	function err(xhr, reason, ex){
   	   alert('loi');
           $("div .box_ajax").html('loi');
         }
   //*****************end order ajax******************/
   });
   
</script>
<div class="baiviet_admin">
   <form method="POST" action="<?php echo base_url().'admin/xuly/video/them';?>">
      <div class="box_heading">
         <div class="icon">
            <img src="<?php echo base_url().'skin/admin/images/icon_sitemap.png';?>"/> 
            Video: <?php 
               if($this->session->userdata('thongbao')){
                   echo '<img src='.base_url().'skin/admin/images/ok.png class="ok"><font color=red><b>'.$this->session->userdata('thongbao').'</b></font>';
                   $this->session->unset_userdata('thongbao');
                   }?>
         </div>
         <div class="right">
            <a href="<?php echo base_url().'admin/xuly/video/edit/';?>"><img src="<?php echo base_url().'skin/admin/images/themmoi.png';?>"/>Thêm mới </a>
         </div>
      </div>
      <div class="box_noidung">
         <table class="form">
            <tr>
               <th class="small_th"><a class="ajax" href="id">id</a><?php if($this->session->userdata('order')=='id'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
               <th ><a title="Tiêu đề" class="ajax" href="name">Tiêu đề</a><?php if($this->session->userdata('order')=='name'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
               <th ><a class="ajax" href="link">Liên kết</a><?php if($this->session->userdata('order')=='url'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
               <th ><a title="Ẩn hiện" class="ajax" href="publish">Status</a><?php if($this->session->userdata('order')=='hien'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
               <th >Sửa</th>
               <th >Xóa</th>
            </tr>
            <?php                      
               $mang[0]="Danh mục gốc"; 
               if(!empty($data)){
                   foreach ($data as $data){
                       echo '
                       <tr>
                       <td>'.$data->id.'</td>
                       <td>'.$data->name.'</td>
                       <td>'.$data->link.'</td>';
                        if($data->publish==1){
                       echo '<td> <div class="ajax_hien" id="p'.$data->id.'" name="'.$table.'/publish/'.$data->id.'/p'.$data->id.'" ></div></td>';
                       }else echo '<td><div  id="p'.$data->id.'" class="ajax_hien untopbot" name="'.$table.'/publish/'.$data->id.'/p'.$data->id.'"></div></td>';								
                                                          
                       echo '
                       <td><a href="'.base_url().'admin/xuly/video/edit/'.$data->id.'" class="edit"><img src="'.base_url().'skin/admin/images/edit.png" title="Sửa"></a></td>
                       <td><a onclick="return confirm(\'Bạn có muốn xóa không?\');" href="'.base_url().'admin/xuly/video/xoa/'.$data->id.'"><img src="'.base_url().'skin/admin/images/xoa.png" title="xóa"></a></td>
                       
                       </tr>                           
                       ';
                   }                          
                                               
               }?>
         </table>
         <!--chon so traang-->
         <div class="chon_trang">
            Số bài hiển thị:
            <select name="sotrang" id="sotrang" class="inputbox" size="1">
            <?php 
               for( $i=10;$i<=100;$i){ 
                   echo '<option value="'.$i.'" ';
                   if($this->session->userdata('rows_per_page_baiviet')==$i){echo 'selected="selected"';}
                   echo '>'.$i.'</option>';
                   $i=$i+10;
               }
               for( $i=200;$i<=500;$i){ 
                   echo '<option value="'.$i.'" ';
                   if($this->session->userdata('rows_per_page_baiviet')==$i){echo 'selected="selected"';}
                   echo '>'.$i.'</option>';
                   $i=$i+100;
               }
                
                ?>
            </select>
         </div>
         <!--end chon so trang-->
         <!--phan trang-->
         <div class="pagination pagination-left">
            <div class="results">
               <span><?php if($result_mensenger){echo $result_mensenger;}?></span>
            </div>
            <ul class="pager">
               <?php	echo $this->pagination->create_links();?>
            </ul>
         </div>
         <!-- end phan trang-->
      </div>
   </form>
</div>
<!--end noi dung bai viet-->
